package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;
    @ApiOperation("新增菜品")
    @PostMapping
    public Result saveDish(@RequestBody DishDTO dishDTO){
        dishService.insertDish(dishDTO);
        return Result.success();
    }
    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result DishQueryingAll(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = dishService.DishQueryingAll(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @ApiOperation("根据Id查菜品")
    @GetMapping("/{id}")
    public Result IdQueryingDish(@PathVariable("id") String id){
        DishVO dishVO = dishService.IdQueryingDish(id);
        return Result.success(dishVO);
    }
    @ApiOperation("修改菜品")
    @PutMapping
    public Result modifyTheDishes(@RequestBody DishDTO dishDTO){
        dishService.modifyTheDishes(dishDTO);
        return Result.success();
    }
    @ApiOperation("菜品起售,停售")
    @PostMapping("/status/{status}")
    public Result dishStatus(@PathVariable("status") String status,String id){
        dishService.dishStatus(status,id);
        return Result.success();
    }
    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/list")
    public Result IdClassification(String categoryId){
        List<Dish> dishes = dishService.IdClassification(categoryId);
        return Result.success(dishes);
    }
    @ApiOperation("批量删除菜品")
    @DeleteMapping
    public Result deleteInBatches2(Integer[] ids){
         String s = dishService.deleteInBatches2(ids);
         if (s!=null)
             return Result.error(s);
         return Result.success();
    }
}
